package com.ruoyi.training.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.training.vo.payment.PreInvoiceVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.training.domain.PreInvoice;
import com.ruoyi.training.service.IPreInvoiceService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 预开票Controller
 * 
 * @author hcc
 * @date 2025-09-29
 */
@RestController
@RequestMapping("/preInvoice")
public class PreInvoiceController extends BaseController
{
    @Autowired
    private IPreInvoiceService preInvoiceService;

    /**
     * 查询预开票列表
     */
    @RequiresPermissions("training:preInvoice:list")
    @GetMapping("/list")
    public TableDataInfo list(PreInvoice preInvoice)
    {
        startPage();
        List<PreInvoice> list = preInvoiceService.selectPreInvoiceList(preInvoice);
        return getDataTable(list);
    }


    /**
     * 查询预开票列表
     */
    @RequiresPermissions("training:preInvoice:list")
    @GetMapping("/getList")
    public TableDataInfo getList(PreInvoiceVo preInvoiceVo)
    {
        startPage();
        List<PreInvoice> list = preInvoiceService.selectList(preInvoiceVo);
        return getDataTable(list);
    }

    /**
     * 导出预开票列表
     */
    @RequiresPermissions("training:preInvoice:export")
    @Log(title = "预开票", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PreInvoice preInvoice)
    {
        List<PreInvoice> list = preInvoiceService.selectPreInvoiceList(preInvoice);
        ExcelUtil<PreInvoice> util = new ExcelUtil<PreInvoice>(PreInvoice.class);
        util.exportExcel(response, list, "预开票数据");
    }

    /**
     * 获取预开票详细信息
     */
    @RequiresPermissions("training:preInvoice:query")
    @GetMapping(value = "/{preInvoiceId}")
    public AjaxResult getInfo(@PathVariable("preInvoiceId") String preInvoiceId)
    {
        return success(preInvoiceService.selectPreInvoiceByPreInvoiceId(preInvoiceId));
    }

    /**
     * 新增预开票
     */
    @RequiresPermissions("training:preInvoice:add")
    @Log(title = "预开票", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PreInvoice preInvoice)
    {
        return toAjax(preInvoiceService.insertPreInvoice(preInvoice));
    }

    /**
     * 修改预开票
     */
    @RequiresPermissions("training:preInvoice:edit")
    @Log(title = "预开票", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PreInvoice preInvoice)
    {
        return toAjax(preInvoiceService.updatePreInvoice(preInvoice));
    }

    /**
     * 删除预开票
     */
    @RequiresPermissions("training:preInvoice:remove")
    @Log(title = "预开票", businessType = BusinessType.DELETE)
	@DeleteMapping("/{preInvoiceIds}")
    public AjaxResult remove(@PathVariable String[] preInvoiceIds)
    {
        return toAjax(preInvoiceService.deletePreInvoiceByPreInvoiceIds(preInvoiceIds));
    }

    /**
     * 批量删除预开票信息
     */
    @RequiresPermissions("training:preInvoice:remove")
    @Log(title = "预开票", businessType = BusinessType.DELETE)
    @PutMapping("/removePreInvoices/{preInvoiceIds}")
    public AjaxResult removePreInvoices(@PathVariable String[] preInvoiceIds)
    {
        return toAjax(preInvoiceService.removePreInvoices(preInvoiceIds));
    }

    /**
     * 预开票关联报名信息
     */
    @RequiresPermissions("training:preInvoice:edit")
    @Log(title = "预开票", businessType = BusinessType.UPDATE)
    @PutMapping("/associationRegistration")
    public AjaxResult associationRegistration(@RequestBody PreInvoice preInvoice)
    {
        return toAjax(preInvoiceService.associationRegistration(preInvoice));
    }

    /**
     * 获取预开票退换票详细信息
     */
    @RequiresPermissions("training:preInvoice:query")
    @GetMapping(value = "/getRefundInfo/{preInvoiceId}")
    public AjaxResult getRefundInfo(@PathVariable("preInvoiceId") String preInvoiceId)
    {
        return success(preInvoiceService.getRefundInfo(preInvoiceId));
    }

    /**
     * 预开票关联信息
     */
    @RequiresPermissions("training:preInvoice:query")
    @GetMapping(value = "/getCorrelationInfo/{preInvoiceId}")
    public AjaxResult getCorrelationInfo(@PathVariable("preInvoiceId") String preInvoiceId)
    {
        return success(preInvoiceService.getCorrelationInfo(preInvoiceId));
    }
}
